/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package statisticaldata;

/**
 *
 * @author chris
 */
public class Sorter {

    private StatisticalData[] prices;

    public Sorter(StatisticalData[] prices) {
        this.prices = prices;
    }

    public StatisticalData[] getPrices() {
        StatisticalData[] pricesCopy = new StatisticalData[prices.length];
        for (int i = 0; i < pricesCopy.length; i++) {
            pricesCopy[i] = prices[i];
        }
        return pricesCopy;
    }

    public void setPrices(StatisticalData[] prices) {
        this.prices = new StatisticalData[prices.length];
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] != null) {
                this.prices[i] = prices[i];
            }
        }
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < prices.length; i++) {
            str.append(prices[i] + " ");
        }
        return str.toString();
    }

    private class SelectionSort implements ISortableData {

        @Override
        public StatisticalData[] sort() {
            int largest;
            for (int i = 0 ; i < prices.length - 1; i++) {
                largest = i;
                for (int j = i + 1; j < prices.length; j++) {
                    if (prices[j].larger(prices[largest])) {
                        StatisticalData temp = prices[j];
                        prices[j] = prices[largest];
                        prices[largest] = temp;
                    }
                }
            }
            return prices;
        }
    }
    
    public SelectionSort getSelectionSort() {
        return new SelectionSort();
    }
}
